//
//  ActivityViewController.m
//  个人项目(豆瓣元旦作业)
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 guoguo. All rights reserved.
//

#import "ActivityViewController.h"
#import "HGTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "ActivityXQViewController.h"
@interface ActivityViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *dataArr;
@property (nonatomic, copy) NSString *str1;
@end

@implementation ActivityViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"活动";
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:30/255.0 green:174/255.0 blue:230/255.0 alpha:1];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    
    //数据处理
    [self handleData];
    
    
    //注册
    
    [_tableView registerClass:[HGTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HGTableViewCell *cell = [[HGTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    
    cell.imageBack1.image = [UIImage imageNamed:@"bg_eventlistcell@2x.png"];
    cell.imageBack2.image = [UIImage imageNamed:@"bg_share_large@2x.png"];
    
    cell.image1.image = [UIImage imageNamed:@"icon_date@2x.png"];
    
    cell.image2.image = [UIImage imageNamed: @"icon_spot@2x.png"];
    
    cell.image3.image = [UIImage imageNamed:@"icon_catalog@2x.png"];
    
    cell.label1.text = @"感兴趣:";
    cell.label2.text = @"参加:";
    
    
    cell.titleLabel.text = _dataArr[indexPath.row][@"title"];
    
    NSString *str1 = _dataArr[indexPath.row][@"begin_time"];
    NSString *str2 = _dataArr[indexPath.row][@"end_time"];
    NSString *str3 = [str1 substringWithRange:NSMakeRange(5, 11)];
    NSString *str4 = [str2 substringWithRange:NSMakeRange(5, 11)];
    cell.timeLabel.text = [str3 stringByAppendingFormat:@"--%@", str4];
    
    cell.addressLabel.text = _dataArr[indexPath.row][@"address"];
    
    cell.typeLabel.text = _dataArr[indexPath.row][@"category_name"];
    
    cell.washLable.text = [_dataArr[indexPath.row][@"wisher_count"] stringValue];
    
    cell.joinLabel.text = [_dataArr[indexPath.row][@"participant_count"] stringValue];
    
    NSString *pash = _dataArr[indexPath.row][@"image_lmobile"];
   [ cell.imagePicture sd_setImageWithURL:[NSURL URLWithString:pash]];
    
    
    
    return cell;
    
}




//点击方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ActivityXQViewController *XQ = [[ActivityXQViewController alloc] init];
   
    
    XQ.mDic = _dataArr[indexPath.row];
    
    XQ.index = indexPath;
    XQ.str = @"hehe";
    
    [self.navigationController pushViewController:XQ animated:YES];
    
    
    
    
}





//分区高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}





//数据处理

- (void)handleData{
    
    NSString *pash = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
    
    self.dataArr = [NSMutableArray arrayWithContentsOfFile:pash];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
